<?php
/**
 *  +----------------------------------------------------------------------
 *  | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
 *  +----------------------------------------------------------------------
 *  | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
 *  +----------------------------------------------------------------------
 *  | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
 *  +----------------------------------------------------------------------
 *  | Author: CRMEB Team <admin@crmeb.com>
 *  +----------------------------------------------------------------------
 */

namespace app\pay;


use app\pay\allinpay\AllinPayv2 as AllinPayService;
use think\Exception;

/**
 * 通联支付
 * Class AllinPay
 * @author 等风来
 * @email 136327134@qq.com
 * @date 2023/2/1
 * @package crmeb\services\pay\storage
 */
class AllinPayv2
{

    /**
     * @var AllinPayService
     */
    protected $pay;
    protected $site_url;

    public function __construct()
    {
        $this->pay = new AllinPayService([
            'appid' => '1546394428142972930',
            'secretKey' => 'FciMQazGzPDUGQiARw9OQoVxA2S9nBxk',
            'cusid' => '552290060518VVA',
            'privateKey' => 'MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCq7ojXjRhso1o7J2qg1/MvoipfSHriM6g+U+P+RFkR68k5sssu0bGTimtG7dGXh6IITnmCX7lAQN4WHKzqvF5HrWvH7zmpKofusqstQMNNzdSSji9/GqbB7MCOVMj72vdcM4EfZsnQAdr8KLVMHf2hFTt09Z4qVgHthwyfiJyR9JraQVmP5WOqYkS31Q3JOLxCAVB7IySY8+Ls2S33ZLOhBk221rJkDOFBQaoYZ40OfPJDuJxRs4tMSzqeitDdSUVoIJVcH3xox8Npzi1ek/unc34lFswS0BH+uSfDFQUhWngjWMZD9lhkpAtXRmRdbyEHN54DRYoGFzM8a1+ve2mjAgMBAAECggEAIn2PTy9BRmqPwm/prBrnDy2Br0hIw2v4/tqenqfb8SnKqMHTDddyJXtAukcyi4jqwRJUomH+V2C/b2bJ3XO08nGj1ewHjoLuetPChpcS0Zg+1HOsUdFm5KqJEC87ftZoI0qhO1zaTAaT0V3Fd1511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1UdDgQWBBSTWNrJgRpU/It/vQa70AZEnA6MRjAdBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUHAwQwDQYJKoZIhvcNAQEFBQADggEBAJLfsxRz7mFbWxycBpMOMxHKf+GjLtDwAjpg+j5oZm75IgWv6f/UoXccudxoxPTLx6JCfm0NskMHmz5QYl9weAwIc7V34c+XCwFbU6EodwCWBJ101R/ITIPVEY5XB1paQsw1VvHLuFC9Pt1QUAWtvmGWzNuKtERuZIK1kruaazA3FEfJ+NO/rprFP2epSvc+iJYN4bYausZbZmenrnH9vCMxoeYZ4AxciFkYkrTP5oqXIDnhJnBA7d33TWpuj5HvpTkxqpZ1l7s8wnAekY6XDoOhoav/lTzjONS3x8zSyc1jav+Ww3bgJgc7YJZqkrevBmWRCJ7opAqPuy4EzxnbBAk=',
            'notifyUrl' => 'https://i.uumo.top/api/pay/notify/allin',
//            'isBeta' => false,
        ]);
        $this->site_url="https://i.uumo.top/";
    }

    /**
     * 创建支付
     * @param string $orderId
     * @param string $totalFee
     * @param string $attach
     * @param string $body
     * @param string $detail
     * @param array $options
     * @return array|mixed
     * @author 等风来
     * @email 136327134@qq.com
     * @date 2023/1/15
     */
    public function create(string $orderId, string $totalFee, string $authcode, string $body,string $notifyUrl)
    {
        $notifyUrl = trim($this->site_url) . $notifyUrl;
        $this->pay->setNotifyUrl($notifyUrl);
        return $this->pay->scanqrPay($totalFee, $orderId,$authcode, $body);
    }
    public function productinfo(string $orderId, string $totalFee, string $authcode, string $body,string $notifyUrl)
    {
        $notifyUrl = trim($this->site_url) . $notifyUrl;
        $this->pay->setNotifyUrl($notifyUrl);
        return $this->pay->productInfo();
    }

    public function merchantPay(string $openid, string $orderId, string $amount, array $options = [])
    {
        throw new Exception('通联支付:暂不支持商家转账');
    }

    /**
     * 发起退款
     * @param string $outTradeNo
     * @param array $options
     * @return array|mixed
     * @author 等风来
     * @email 136327134@qq.com
     * @date 2023/1/15
     */
    public function refund(string $outTradeNo, array $options = [])
    {
        return $this->pay->refund($options['refund_price'], $options['order_id'], $outTradeNo);
    }

    public function queryRefund(string $outTradeNo, string $outRequestNo, array $other = [])
    {
        // TODO: Implement queryRefund() method.
    }

}
